package model

import (
	"gorm.io/gorm"
	"time"
	"video-srv/basic/config"
)

type Video struct {
	Id          uint32         `gorm:"column:id;type:int UNSIGNED;primaryKey;not null;" json:"id"`
	Title       string         `gorm:"column:title;type:varchar(60);comment:标题;not null;" json:"title"`           // 标题
	Image       string         `gorm:"column:image;type:varchar(300);comment:封面;not null;" json:"image"`          // 封面
	Info        string         `gorm:"column:info;type:varchar(80);comment:简介;not null;" json:"info"`             // 简介
	VideoListId int32          `gorm:"column:video_list_id;type:int;comment:剧集ID;not null;" json:"video_list_id"` // 剧集ID
	CreatedAt   time.Time      `gorm:"column:created_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"created_at"`
	UpdatedAt   time.Time      `gorm:"column:updated_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"updated_at"`
	DeletedAt   gorm.DeletedAt `gorm:"column:deleted_at;type:datetime(3);default:NULL;" json:"deleted_at"`
}

func (v *Video) TableName() string {
	return "video"
}

func (v *Video) GetList() (list []*Video, err error) {
	err = config.DB.Find(&list).Error
	return
}

func (v *Video) AddVideo() error {
	return config.DB.Create(&v).Error
}
